Skip to content

add/preserve const in dynamic_cast#4655

Merged
danmar merged 2 commits intocppcheck-opensource:mainfrom
firewave:cast
Dec 19, 2022
Merged

add/preserve const in dynamic_cast#4655
danmar merged 2 commits intocppcheck-opensource:mainfrom
firewave:cast

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

This were found during manual code review of misc-const-correctness warnings.

@firewave
Copy link
Copy Markdown
Collaborator Author

firewave commented Dec 19, 2022

For the case where the dynamic_cast lacked the const I filed a ticket: https://trac.cppcheck.net/ticket/11224.

This might leverage improved detection of constParameter: https://trac.cppcheck.net/ticket/11225.

@firewave firewave marked this pull request as ready for review December 19, 2022 13:13
@chrchr-github
Copy link
Copy Markdown
Collaborator

Maybe we should use auto p = dynamic_cast... in these cases?

@firewave
Copy link
Copy Markdown
Collaborator Author

The usage of auto was discouraged in the past but that appears to be no longer the case.

I would prefer to address this in a different PR which turns on the mondernize-use-auto clang-tidy warning.

@chrchr-github
Copy link
Copy Markdown
Collaborator

I see. Since this is pretty much the canonical use case for auto (avoids repeating the type), I don't think there would be objections.

@danmar danmar merged commit 6fedbb4 into cppcheck-opensource:main Dec 19, 2022
@firewave firewave deleted the cast branch December 19, 2022 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants